<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

if (!defined('DS')) define('DS', DIRECTORY_SEPARATOR);

class com_recipes extends OC_Controller {

	function __construct()
	{
		parent::__construct();
		$this->load->model('comments/comment_model','mm');
	}

	function _remap($method, $params = array())
	{
		parent::_remap($method, $params);
		
		if (method_exists($this, $method))
			return call_user_func_array(array($this, $method), $params);
		else
			show_404();
	}

	function init_header()
	{
		$this->header['jeasyui'] 	= TRUE;
		$this->header['source_bot'] = array(
			script_tag(site_url('widget/themescript/moment.js')),
			script_tag(site_url('comments/themescript/app/cr.js'))
		);
	}

	function index()
	{
		$this->init_header();
		$this->header['nav'] = 'comments';
		$this->header['pagetitle'] = 'Comments';
		$this->view('comments/ca_view');
	}

	function load_data()
	{
		$params = $this->input->post();
		$result = $this->mm->load_com_recipes($params);
		print(json_encode($result));
	}

	function approve()
	{
		$post = $this->input->post();
		$this->mm->cr_approve(array('cr_id' => $post['cr_id']));
		print(json_encode(array(
			'success' => TRUE
		)));
	}

	function reject()
	{
		$post = $this->input->post();
		$this->mm->cr_reject(array('cr_id' => $post['cr_id']));
		print(json_encode(array(
			'success' => TRUE
		)));
	}

}